﻿using System.Collections.Generic;

namespace Game.FlowField
{
    public static class ObjectPool<T>
    {
        private static object s_Lock = new object();
        private static Stack<T> s_Cache = new Stack<T>();

        public static void Cache(T item)
        {
            lock (s_Lock)
            {
                s_Cache.Push(item);
            }
        }

        public static bool TryGet(out T result)
        {
            lock (s_Lock)
            {
                return s_Cache.TryPop(out result);
            }
        }
    }
}